#!/bin/bash

g_Sh_Pro_Path=$(pwd)/..
source $g_Sh_Pro_Path/ComEchoType.sh

pro_name="$1"
chip_name="$2"
$g_Sh_Pro_Path/ComBuildFunc.sh $g_Sh_Pro_Path $pro_name $chip_name "ProductTest"
if [ $? -eq 0 ];then
    exit
else
    tool_strip=`cat $g_Sh_Pro_Path/ToolStrip.txt`
fi

g_Sh_ProductTest_Path=$(pwd)
g_Sh_Ipc_Code_Path=$g_Sh_Pro_Path/IPC_Code

mkdir -p build/$chip_name
cd build/$chip_name
rm bin/* -rf
cmake -Wno-dev -DCHIP_TYPE=$chip_name -D$chip_name:BOOL=ON -D"ProductTest":BOOL=ON \
-DCMAKE_TOOLCHAIN_FILE=$g_Sh_Ipc_Code_Path/Cmake/$chip_name.cmake ../..
make -j4

$tool_strip bin/*
if [ ! -d $g_Sh_ProductTest_Path/product_test_tools ];then
    mkdir -p $g_Sh_ProductTest_Path/product_test_tools
    chmod 777 $g_Sh_ProductTest_Path/product_test_tools
fi

if [ ! -d $g_Sh_ProductTest_Path/product_test ];then
    mkdir -p $g_Sh_ProductTest_Path/product_test
    chmod 777 $g_Sh_ProductTest_Path/product_test
fi

rm $g_Sh_ProductTest_Path/product_test_tools/* -r
cp bin/burn_uid $g_Sh_ProductTest_Path/product_test_tools

rm $g_Sh_ProductTest_Path/product_test/* -r
cp -dp $g_Sh_ProductTest_Path/lib/$chip_name/* $g_Sh_ProductTest_Path/product_test/
cp bin/hardware_test $g_Sh_ProductTest_Path/product_test/

cd $g_Sh_ProductTest_Path/
tar cf product_test.tar hardware_test
cp product_test.tar /tftp/
cp product_test.tar /var/www/html/
sh_func_echo_info "product_test.tar is in product_test_tools"
mv product_test.tar product_test_tools
g_now_time=`date +%Y-%m-%d_%H-%M-%S`
touch product_test_tools/$chip_name"_"$pro_name"_"$g_now_time
$g_Sh_Pro_Path/ComBuildFunc.sh $g_Sh_Pro_Path $pro_name $chip_name "ProductTest" "s"
